//
//  ESTWorkSpaceViewController.m
//  ESTSCRMAPP
//
//  Created by 李贤立 on 2018/11/2.
//  Copyright © 2018年 Capfer. All rights reserved.
//

#import "ESTWorkSpaceViewController.h"
#define HeaderViewHeight         180
#define HeaderViewReviseHeight   70
@interface ESTWorkSpaceViewController ()<UITableViewDelegate, UITableViewDataSource>
/**
 *  TableView
 */
@property(nonatomic, strong) TYZTableView *tableView;
/**
 *  页码
 */
@property(nonatomic, assign) NSInteger page_num;
/**
 *  数据源
 */
@property(nonatomic, strong) NSMutableArray *modelArray;
@end

@implementation ESTWorkSpaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTitleView];
    [self setupTableView];
}
#pragma mark - 设置UI
- (void)setupTitleView {
    TYZView *titleView = [[TYZView alloc] init];
    [self.view addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(DE_NavigationHeight);
    }];
    titleView.backgroundColor = ThemeColor;
    TYZLabel *titleLabel = [[TYZLabel alloc] init];
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(titleView);
        make.bottom.equalTo(titleView).offset(-10);
    }];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = [@"工作圈" S];
    titleLabel.font = [UIFont boldSystemFontOfSize:CoreInfo.fontSize * 1.2];
    titleLabel.textColor = TYZWhiteColor;
}
- (void)setupTableView {
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(DE_NavigationHeight);
    }];
    
    TYZView *headerView = [[TYZView alloc] init];
    headerView.backgroundColor = TYZWhiteColor;
    headerView.bounds = CGRectMake(0, 0, kWindowWidth, HeaderViewHeight + HeaderViewReviseHeight);
    UIImage *image = [UIImage imageNamed:@"loginBG"];
    CGFloat height = image.size.height * (kWindowWidth / image.size.width);
    TYZImageView *iconView = [[TYZImageView alloc] initWithImage:image];
    [headerView addSubview:iconView];
    iconView.frame = CGRectMake(0, HeaderViewHeight - height + HeaderViewReviseHeight, kWindowWidth, height);
    iconView.layer.masksToBounds = YES;
    
    TYZView *spaceView = [[TYZView alloc] init];
    [headerView addSubview:spaceView];
    spaceView.frame = CGRectMake(0, HeaderViewHeight, kWindowWidth, HeaderViewReviseHeight);
    spaceView.backgroundColor = TYZWhiteColor;
    
    TYZView *headerImageView = [[TYZView alloc] init];
    headerImageView.backgroundColor = TYZWhiteColor;
    [headerView addSubview:headerImageView];
    [headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(headerView).offset(-20);
        make.centerY.equalTo(spaceView.mas_top).offset(-10);
        make.width.height.mas_equalTo(61);
    }];
    TYZImageView *headerImage = [[TYZImageView alloc] init];
    [headerImageView addSubview:headerImage];
    [headerImage loadURLImageWithURLString:UserInfo.EMP_INFO.firstObject.HEAD_PORTRAIT_URL playceholderImageType:PlayceholderImageTypePeople];
    [headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(headerImageView).offset(1);
        make.right.bottom.equalTo(headerImageView).offset(-1);
    }];
    TYZButton *coverButton = [[TYZButton alloc] init];
    [headerImageView addSubview:coverButton];
    [coverButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(headerImageView);
    }];
    [coverButton addTarget:self action:@selector(didClickHeaderImageButton) forControlEvents:UIControlEventTouchUpInside];
    
    TYZLabel *nameLabel = [[TYZLabel alloc] init];
    nameLabel.text = UserInfo.EMP_INFO.firstObject.EMPLOYEE_NAME;
    [headerImageView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(headerImage);
        make.right.equalTo(headerImage.mas_left).offset(-10);
    }];
    nameLabel.textColor = TYZWhiteColor;
    nameLabel.font = TYZFont(CoreInfo.fontSize);
    
    self.tableView.tableHeaderView = headerView;
    
    [self setupTableViewHeader];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ESTWorkSpaceViewControllerCell"];
}
- (void)didClickHeaderImageButton {
    
}
- (void)pullDownRefreshData {
    self.page_num = 1;
    [self.modelArray removeAllObjects];
    [self acquireData];
}
- (void)pullUpLoadMore {
    self.page_num++;
    [self acquireData];
}
- (void)setupTableViewHeader {
    WEAKSELF
    self.tableView.mj_header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
//        [weakSelf pullDownRefreshData];
        [weakSelf.tableView.mj_header endRefreshing];
    }];
    [self.tableView bringSubviewToFront:self.tableView.mj_header];
    MJRefreshStateHeader *stateHeader = (MJRefreshStateHeader *)self.tableView.mj_header;
    stateHeader.textColor = TYZWhiteColor;
}
- (void)setupTableViewFooter {
    WEAKSELF
    self.tableView.mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        [weakSelf pullUpLoadMore];
    }];
}
- (void)acquireData {
    
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [NSString stringWithFormat:@"%ld", (long)section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ESTWorkSpaceViewControllerCell" forIndexPath:indexPath];
    return cell;
}
#pragma mark - setter & getter
- (TYZTableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[TYZTableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
@end
